package xyz.xtt.admin.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.Builder;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import xyz.xtt.admin.entity.TblAdminUser;
import xyz.xtt.admin.utils.Md5Util;

@Data
public class UserRequest {
    @NotNull(groups = Update.class)
    private Integer id;

    @NotBlank(message = "用户名不能为空")
    @Length(max = 20, min = 4, message = "用户名格式不正确")

    private String userName;
    @NotBlank(message = "密码不能为空", groups = Add.class)
    @Length(max = 20, min = 5, message = "用户名密码格式不正确", groups = Add.class)
    private String password;


    private String nickName;


    public TblAdminUser create() {
        String pwd = Md5Util.getMD5String(this.password);
        return TblAdminUser.builder().userName(this.userName).nickName(this.nickName).password(pwd).build();
    }

    public interface Add extends Default {}
    public interface Update extends Default {}
}
